import React from 'react';
import {observer} from 'mobx-react';
import {WeaDialog} from 'ecCom';
import {WeaTableNew} from 'comsMobx';
import {Button} from 'antd';
import RequestList from './request-list/index';

const WeaTable = WeaTableNew.WeaTable;

@observer

export default class Main extends React.Component{

    constructor(props) {
        super(props);
        this.state = {
            visible : false,   //弹出框的显隐
            requestidRange : ''   //当前行的requestids
        }
    }

    viewModalCancel () {
        this.setState({visible:false})
    }

    getFooter () {
        let btns = [];
        btns.push(
            <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@aqw3kp@viewModalCancel`} type='glost' onClick={()=>this.viewModalCancel()}>取消</Button>
        )
        return btns;
    }

    render () {

        let { tableStore} = this.props;
        let {visible,requestidRange} = this.state;
        return (
            <div>
                <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@e16l3e`}
                    comsWeaTableStore={tableStore}
                    hasOrder={true}
                    needScroll={true}
                    getColumns={(columns)=>this.props.getColumns && this.props.getColumns(columns)}
                    uniqueId={true}
                    onOperatesClick={this.onOperatesClick.bind(this)}
                    tableWidth={this.getTableWidth}
                />
                <RequestList ecId={`${this && this.props && this.props.ecId || ''}_RequestList@74l5hr`} modalVisible={visible} dataParams={{'requestidRange':requestidRange,'externalKey':'report','isExternal':'true'}} closerReqListModal={this.doCloseModal.bind(this)}/>
            </div>
        )
    }

    doCloseModal(){
        this.setState({visible:false,requestidRange:''});
    }

    onOperatesClick(record, index, operate, flag){
        if(flag==="0"){
            const {requestids = ''} = record;
            this.setState({visible:true,requestidRange:requestids});
        }
    }

    getTableWidth(columns) {
        let showLength = columns.filter((col) => col.display == 'true').length;
        return 10 * showLength + "%";//也支持返回固定值，如果小于100%,不会生效。
    }

}